package com.stylefeng.guns.modular.salesmanagement.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.model.PurchaseGoods;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.CustomerReturnList;
import com.stylefeng.guns.modular.salesmanagement.service.ICustomerReturnListService;

/**
 * 客户退货查询控制器
 *
 * @author fengshuonan
 * @Date 2018-09-12 21:30:23
 */
@Controller
@RequestMapping("/customerReturnList")
public class CustomerReturnListController extends BaseController {

    private String PREFIX = "/salesmanagement/customerReturnList/";

    @Autowired
    private ICustomerReturnListService customerReturnListService;

    /**
     * 跳转到客户退货查询首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "customerReturnList.html";
    }

    /**
     * 跳转到添加客户退货查询
     */
    @RequestMapping("/customerReturnList_add")
    public String customerReturnListAdd() {
        return PREFIX + "customerReturnList_detail.html";
    }

    /**
     * 跳转到订单的商品列表详情
     * @return 页面
     */
    @RequestMapping("/customerReturnList_detail/{customerReturnId}/{returnOrderNumber}")
    public String customerReturnListDetail(@PathVariable(value = "customerReturnId") Long customerReturnId,
                                           @PathVariable(value = "returnOrderNumber") String returnOrderNumber,
                                           Model model){
        model.addAttribute("customerReturnId", customerReturnId);
        model.addAttribute("returnOrderNumber", returnOrderNumber);
        return PREFIX + "customerReturnList_detail.html";
    }

    /**
     * 跳转到修改客户退货查询
     */
    @RequestMapping("/customerReturnList_update/{customerReturnListId}")
    public String customerReturnListUpdate(@PathVariable Integer customerReturnListId, Model model) {
        CustomerReturnList customerReturnList = customerReturnListService.selectById(customerReturnListId);
        model.addAttribute("item",customerReturnList);
        LogObjectHolder.me().set(customerReturnList);
        return PREFIX + "customerReturnList_edit.html";
    }

    /**
     * 获取客户退货查询列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return customerReturnListService.selectList(null);
    }

    /**
     * 新增客户退货查询
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CustomerReturnList customerReturnList) {
        customerReturnListService.insert(customerReturnList);
        return SUCCESS_TIP;
    }

    /**
     * 删除客户退货查询
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer customerReturnListId) {
        customerReturnListService.deleteById(customerReturnListId);
        return SUCCESS_TIP;
    }

    /**
     * 修改客户退货查询
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CustomerReturnList customerReturnList) {
        customerReturnListService.updateById(customerReturnList);
        return SUCCESS_TIP;
    }

    /**
     * 客户退货查询详情
     */
    @RequestMapping(value = "/detail/{customerReturnListId}")
    @ResponseBody
    public Object detail(@PathVariable("customerReturnListId") Integer customerReturnListId) {
        EntityWrapper<CustomerReturnList> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("customer_return_id",customerReturnListId);
        return customerReturnListService.selectList(entityWrapper);
    }
}
